import * as CryptoJS from '@/static/js/crypto-js.min.js';
export class Tools {
	/**
	 * 判断是否是数字
	 * @param {Any} checkVal  
	 * @return {boolean} true是数字
	 */
	static isNumber(checkVal) {
		var reg = /^-?[1-9][0-9]?.?[0-9]*$/;
		return reg.test(checkVal);
	}
	/**
	 * 判断是不是从0开始的正整数
	 * @param {Object} checkVal
	 */
	static isPositiveNum(checkVal){
		var reg = /^(0|[1-9][0-9]*)$/;
		return reg.test(checkVal);
	}
	/**
	 * 两个json的数据合并
	 * @param {Object} jsonbject1 json的对象  {"a":"aa"} 
	 * @param {Object} jsonbject2  json的对象
	 * @return {Object} 返回合并后的数据
	 */
	static concat(jsonbject1, jsonbject2) {
		var resultJsonObject = {};
		for (var attr in jsonbject1) {
			resultJsonObject[attr] = jsonbject1[attr];
		}
		for (var attr2 in jsonbject2) {
			resultJsonObject[attr2] = jsonbject2[attr2];
		}
		return resultJsonObject;
	}
	/**
	 * 判断数据是否为空
	 * @param {Any} obj
	 * @return{boolean} 空为true，不空为false
	 */
	static isEmpty(obj) {
		if (typeof obj === "undefined" || obj === null || obj === "Null" || obj === "null" || obj === "" || JSON.stringify(
				obj) === '{}') {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 判断字符串是否是对象
	 * @param {Any} email
	 * @return {boolean} 为true是邮箱 
	 */
	static isEmail(email) {
		let myVerify = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
		if (myVerify.test(email)) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 是否是身份证卡
	 * 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
	 * @param {Any} s  身份证号
	 * @return {boolean}返回ture是身份证号
	 */
	static isIdCard(s) {
		return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(s);
	}
	/**
	 * 去除空格中的字符串
	 * @param {String} text
	 * @return {boolean} 去除空格的字符串
	 */
	static trim(text) {
		if (typeof(text) == "string") {
			return text.replace(/^\s*|\s*$/g, "");
		} else {
			return text;
		}
	}
	/**
	 * 是否是url
	 * @param {Any} s 目标对象
	 * @return {boolean}  true是url
	 */
	static isUrl(s) {
		return /^http[s]?:\/\/.*/.test(s);
	}
	/**
	 * 是否是小数或整数
	 * @param {Any} s   数据
	 * @return { boolean} true是小数或整数
	 */
	static isDecimal(s) {
		return /^\d+$|^\d*\.\d+$/.test(s);
	}
	/**
	 * 保留两位小数位
	 * @param {Any} num
	 * @return {Number} 保留两位的小数
	 */
	static keepTwoDecimal(num) {
		var result = parseFloat(num);
		if (isNaN(result)) {
			return false;
		}
		result = Math.round(num * 100) / 100;
		return result.toFixed(2);
	}
	/**
	 * 保留三位小数位
	 * @param {Any} num
	 * @return {Number} 保留三位的小数
	 */
	static keepThreeDecimal(num) {
		var result = parseFloat(num);
		if (isNaN(result)) {
			return false;
		}
		result = Math.round(num * 1000) / 1000;
		return result;
	}
	/**
	 * 判断输入的是否是金额的数据
	 * @param {Any} obj 目标数据
	 * @return { boolean } 
	 */
	static isPrice(obj) {
		var objRegExp = /^[0-9]+(.[0-9]{1,2})?$/;
		return objRegExp.test(obj);
	}
	/**
	 * 只能够输入金额数字
	 * @param value  输入的源数据
	 * @param {boolean} notMinus  true输入非负数，false输出负数
	 * @param {boolean} isInt  是否整数
	 * @return {number} 返回金额的数字
	 */
	static moneyFormat(value, notMinus, isInt = false) {
		// 先把非数字的都替换掉，除了数字负号和点
		value = !!notMinus ? value.replace(/[^\d.]/g, '') : value.replace(/[^-\d.]/g, '');
		// 必须保证第一个不是.
		value = value.replace(/^\./g, '');
		// 保证只有出现一个.而没有多个.
		value = value.replace(/\.{2,}/g, '.');
		// 保证.只出现一次，而不能出现两次以上
		value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
		// 只能两位小数点
		if (isInt) {
			value = value.substring(0, value.indexOf('.') === -1 ? value.length : (value.indexOf('.')));
		} else {
			value = value.substring(0, value.indexOf('.') === -1 ? value.length : (value.indexOf('.') + 3));
		}
		return value;
	}

	/**
	 * http中的get访问的一个参数的拼接
	 * @param {Any} baseParam  是{}的对象
	 * @param {string} url 目标url
	 * @return {string} 将{}的对象拼接到url上面来
	 */
	static Urlsplice(baseParam, url) {
		let paramsArray = [];
		Object.keys(baseParam).forEach(key => paramsArray.push(key + '=' + baseParam[key]));
		if (!(/\?/.test(url))) {
			url += '?' + paramsArray.join('&');
		} else {
			url += '&' + paramsArray.join('&');
		}
		return url;
	}

	/**
	 * 获取目标一维数组，几个元素组合
	 * @param{Array} targetArr 目标一维数组
	 * @param {boolean}isAll true是全组合，false结合selectNum的参数使用
	 * @param{int} selectNum 选择几个元素组合,isAll为false才有用
	 */
	static arrayCombine(targetArr, isAll, selectNum) {
		if (!targetArr || !targetArr.length) {
			return [];
		}
		var len = targetArr.length;
		var resultArrs = [];
		for (var n = 1; n < len; n++) {
			var flagArrs = this.getFlagArrs(len, n);
			while (flagArrs.length) {
				var flagArr = flagArrs.shift();
				var combArr = [];
				for (var i = 0; i < len; i++) {
					flagArr[i] && combArr.push(targetArr[i]);
				}
				if (isAll) { // 所有组合
					resultArrs.push(combArr);
				} else {
					if (combArr.length == selectNum) {
						resultArrs.push(combArr.join(','));
					}
				}
			}
		}
		return resultArrs;
	}

	/**
	 * 获得从m中取n的所有组合做为一个中间获取组合的的数据 在arrayCombine中被调用
	 */
	static getFlagArrs(m, n) {
		if (!n || n < 1) {
			return [];
		}
		var resultArrs = [],
			flagArr = [],
			isEnd = false,
			i, j, leftCnt;
		for (i = 0; i < m; i++) {
			flagArr[i] = i < n ? 1 : 0;
		}
		resultArrs.push(flagArr.concat());
		while (!isEnd) {
			leftCnt = 0;
			for (i = 0; i < m - 1; i++) {
				if (flagArr[i] == 1 && flagArr[i + 1] == 0) {
					for (j = 0; j < i; j++) {
						flagArr[j] = j < leftCnt ? 1 : 0;
					}
					flagArr[i] = 0;
					flagArr[i + 1] = 1;
					var aTmp = flagArr.concat();
					resultArrs.push(aTmp);
					if (aTmp.slice(-n).join("").indexOf('0') == -1) {
						isEnd = true;
					}
					break;
				}
				flagArr[i] == 1 && leftCnt++;
			}
		}
		return resultArrs;
	}

	/**
	 * 数组和数组的组合
	 * @param [Array] arr 一个二位数组，如下:   [[1,2],[3,4]]  组合后1,3|1,4|2,3|2,4
	 * @return {Array} 返回组合后的数值
	 */
	static doExchange(arr) {
		var len = arr.length;
		// 当数组大于等于2个的时候
		if (len >= 2) {
			// 第一个数组的长度
			var len1 = arr[0].length;
			// 第二个数组的长度
			var len2 = arr[1].length;
			// 2个数组产生的组合数
			var lenBoth = len1 * len2;
			//  申明一个新数组
			var items = new Array(lenBoth);
			// 申明新数组的索引
			var index = 0;
			for (var i = 0; i < len1; i++) {
				for (var j = 0; j < len2; j++) {
					if (arr[0][i] instanceof Array) {
						items[index] = arr[0][i].concat(arr[1][j]);
					} else {
						items[index] = [arr[0][i]].concat(arr[1][j]);
					}
					index++;
				}
			}
			var newArr = new Array(len - 1);
			for (var i = 2; i < arr.length; i++) {
				newArr[i - 1] = arr[i];
			}
			newArr[0] = items;
			return this.doExchange(newArr);
		} else {
			return arr[0];
		}
	}
	/**
	 * 获取UUID
	 * @param len  开始截取位置
	 * @param radix  结束截取的最后位置
	 * @return {String}  返回目标值
	 */

	static UUID(len, radix) {
		var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
		var chars = CHARS,
			uuid = [],
			i;
		radix = radix || chars.length;
		if (len) {
			for (i = 0; i < len; i++) { //Compact form 
				uuid[i] = chars[0 | Math.random() * radix];
			}
		} else {
			// rfc4122, version 4 form  
			var r;
			// rfc4122 requires these characters  
			uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
			uuid[14] = '4';
			// Fill in random data.  At i==19 set the high bits of clock sequence as  
			// per rfc4122, sec. 4.1.5  
			for (i = 0; i < 36; i++) {
				if (!uuid[i]) {
					r = 0 | Math.random() * 16;
					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
				}
			}
		}
		return uuid.join('');
	}

	/**
	 * 获取资源的路径
	 * @param{String} filePath 文件的路径
	 * @return {boolean} ture是图片资源
	 */
	static isAssetTypeAnImage(filePath) {
		let ext = filePath.substr(filePath.lastIndexOf(".") + 1)
		// 'webp', 'psd', 'svg', 'tiff'
		return ['png', 'jpg', 'jpeg', 'bmp', 'gif'].indexOf(ext.toLowerCase()) !== -1;
	}
	/**
	 * 时间戳格式(是否隐藏小时)
	 * @param seconds 时间戳
	 * @param isHideHour  是否隐藏小时 
	 */
	static formateTime(seconds, isHideHour = false) {
		if (seconds <= 0) {
			return '00:00';
		}
		let hourStr;
		let minuteStr;
		let secondsStr;
		var hour = Math.floor(seconds / 3600);
		seconds = seconds - hour * 3600;
		var minute = Math.floor(seconds / 60);
		seconds = seconds - minute * 60;
		if (hour < 10) {
			hourStr = "0" + hour;
		} else {
			hourStr = "" + hour;
		}
		if (minute < 10) {
			minuteStr = "0" + minute;
		} else {
			minuteStr = "" + minute;
		}
		if (seconds < 10) {
			secondsStr = "0" + seconds;
		} else {
			secondsStr = "" + seconds;
		}
		if (isHideHour && hourStr == '00') {
			return minuteStr + ':' + secondsStr;
		}
		return hourStr + ':' + minuteStr + ':' + secondsStr;
	}
	/**
	 * 开始时间和结束时间比较大小
	 * @param {Object} startTime  开始的时间(时间日期的字符串)
	 * @param {Object} endTime
	 */
	static compareDate(startTime, endTime) {
		let tempStart = new Date(Date.parse(startTime));
		let tempEnd = new Date(Date.parse(endTime));
		return endTime >= startTime;
	}

	/**
	 * 判断运行的平台设备是weixin,android还是ios的浏览器
	 * @return  weixin,android或ios
	 */
	static getPlatform() {
		let dirviceType = "";
		let u = navigator.userAgent
		var ua = u.toLowerCase();
		if (ua.indexOf('micromessenger') != -1) {
			dirviceType = "weixin";
		}
		if (this.platform.is("android")) {
			dirviceType = "android";
		}
		if (this.platform.is("ios")) {
			dirviceType = "ios";
		}
		return dirviceType;
	}
	/**
	 * 将obj的json转为string的json
	 * @param {Object} data    是object的json数据
	 * @return 返回string的json格式的数据
	 */
	static objJsonToStringJson(data) {
		if (!this.isEmpty(data)) {
			if (typeof(data) == "string") {
				return data;
			} else {
				return JSON.stringify(data);
			}
		} else {
			return "{}";
		}
	}
	/**
	 * 验证是否是手机号
	 * @param {Object} inputNumber  手机号码
	 * @return true是手机号，false不是手机号
	 */
	static isMobilePhoneNumber(inputNumber) {
		let myVerify = new RegExp("^[1][3,4,5,7,8][0-9]{9}$");
		if (myVerify.test(inputNumber)) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 对html的数据进行转码
	 * @param {Object} text  是一段html的数据
	 * @return 返回转码后的html
	 */
	static htmlEncode(text) {
		return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
	}
	/**
	 * 判断是否是string的字符串
	 * @param {Object} str  string型的json字符串
	 */
	static isStringJson(str) {
		if (typeof str == 'string') {
			try {
				var obj = JSON.parse(str);
				if (typeof obj == 'object' && obj) {
					return true;
				} else {
					return false;
				}
			} catch (e) {
				return false;
			}
		}
	}
	/**
	 * 判断是否是json对象
	 */
	static jsJson(str, pass_object = false) {
		let that = this;
		if (pass_object && (Object.prototype.toString.call(str) === '[object Object]')) {
			return true;
		}
		if (!(Object.prototype.toString.call(str) === '[object String]')) {
			return false;
		}
		str = str.replace(/\s/g, '').replace(/\n|\r/, '');
		if (/^\{(.*?)\}$/.test(str)) {
			return /"(.*?)":(.*?)/g.test(str);
		}
		if (/^\[(.*?)\]$/.test(str)) {
			return str.replace(/^\[/, '')
				.replace(/\]$/, '')
				.replace(/},{/g, '}\n{')
				.split(/\n/)
				.map(function(s) {
					return that.jsJson(s);
				})
				.reduce(function(prev, curr) {
					return !!curr;
				});
		}
		return false;
	}
	/** 
	 * 判断一个数组中是否存在某一个键值
	 * @param {Array} ary  目标数值
	 * @param {String} key  目标键值
	 * @return { boolean }  true是存在key值
	 */
	static isExitKey(ary, key) {
		if (ary.hasOwnProperty(key)) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 获取当前时间的年月日
	 * @param seperator1 年月日的分割符号
	 * @return { String} 目标的年月日时间
	 */
	static getNowFormatDate(seperator1 = "-") {
		let date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let strDate = date.getDate();
		let resMonth = "";
		let resDate = "";
		if (month >= 1 && month <= 9) {
			resMonth = "0" + month;
		} else {
			resMonth = month + "";
		}
		if (strDate >= 0 && strDate <= 9) {
			resDate = "0" + strDate;
		} else {
			resDate = strDate + "";
		}
		let currentdate = year + seperator1 + resMonth + seperator1 + resDate;
		return currentdate;
	}
	/**
	 * AES加密
	 * @param data 
	 */
	static aesEncode(data, isForce) {
		let encrypt = Tools.getBodyAttribute("encrypt");
		encrypt = (!Tools.isEmpty(encrypt) && encrypt == '1') ? 1 : 0;
		if (encrypt == 1 || isForce) {
			let tempData = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(Config.AES_KEY), {
				mode: CryptoJS.mode.ECB,
				padding: CryptoJS.pad.Pkcs7,
				iv: '',
			}).toString();
			return new Buffer(tempData).toString('base64');
		} else {
			return data;
		}
	}

	/**
	 * AES解密
	 * @param data 
	 */
	static aesDecode(data, isForce) {
		let encrypt = Tools.getBodyAttribute("encrypt");
		encrypt = (!Tools.isEmpty(encrypt) && encrypt == '1') ? 1 : 0;
		if (encrypt == 1 || isForce) {
			const decipher = CryptoJS.AES.decrypt((new Buffer(data, 'base64')).toString(), CryptoJS.enc.Utf8.parse(
				ConfigService.AES_KEY), {
				mode: CryptoJS.mode.ECB,
				padding: CryptoJS.pad.Pkcs7,
				iv: '',
			});
			// 将解密对象转换成 UTF8 的字符串
			const resultDecipher = CryptoJS.enc.Utf8.stringify(decipher);
			// 返回解密结果
			return resultDecipher;
		} else {
			return data;
		}

	}

	static aesDecodeToJson(data, isForce = false) {
		let res = this.aesDecode(data, isForce);
		if ((typeof res) != 'string') {
			res = JSON.stringify(res)
		}
		if (this.jsJson(res)) {
			return JSON.parse(res);
		} else {
			return {};
		}
	}

	/**
	 * 获取body元素上面的属性值
	 * @param {String} key  body元素上面的属性的值
	 * @return {String} 获取的属性的值
	 */
	static getBodyAttribute(key) {
		return VueTools.getStorageSync(key);
	}

	/**
	 * 设置body元素的熟悉值
	 * @param {String} key body属性的key
	 * @param {String} value  body属性key的值
	 */
	static setBodyAttribute(key, value) {
		VueTools.setStorageSync(key, value);
	}
	/**
	 * 替换第一次出现的字符
	 * @param {Object} strTarget  模板字符串
	 * @param {Object} charTarget  需要替换目标字符
	 * @param {Object} replaceChar  替换的字符
	 */
	static replaceFirstChar(strTarget, charTarget, replaceChar) {
		return strTarget.replace(charTarget, replaceChar);
	}
	/**
	 * 通过key删除一维数组的数据
	 * @param {*} arr  目标数据  [{"itemID":'1',"name":"a"},{"itemID":'2',"name":"b","row":"0.9"},{"itemID":'20',"name":"c","test":"22222"}]
	 * @param {*} key 
	 * @param {*} value 
	 * deleteObjByKey(目标数据,"itemID",20)
	 */
	static deleteObjByKey(arr,key,value){
		if(arr instanceof Array){
			for(let i=0; i<arr.length;i++){
				if(arr[i][key]+""==value+""){
					arr.splice(i,1);
					break;
				}
			}
			return arr
		}else{
			return arr;
		}
	}

	/**
	 * 判断一维对象数组的对象中是否存在某一值
	 * @param {*} arr 目标数据 [{"itemID":'1',"name":"a"},{"itemID":'2',"name":"b","row":"0.9"},{"itemID":'20',"name":"c","test":"22222"}]
	 * @param {*} key 
	 * @param {*} value 
	 * isExitObjKey(目标数据,"itemID","20");
	 */
	static isExitObjKey(arr,key,value){
		let res=false;
		for(let i=0; i<arr.length;i++){
			if((arr[i][key]+"")==(value+"")){
				res=true;
				break;
			}
		}
		return res;
	}

	/**
	 * 获取存在数组对象中的下标
	 * @param {*} arr 
	 * @param {*} key 
	 * @param {*} value 
	 */
	static getObjKeyIndex(arr,key,value){
		let res=-1;
		for(let i=0; i<arr.length;i++){
			if((arr[i][key]+"")==(value+"")){
				res=i;
				break;
			}
		}
		return res;
	}

	static  h5Copy(content){
		  let input = document.createElement("input")
		  input.value = content
		  input.readOnly = "readOnly"
		  document.body.appendChild(input)
		  input.select() // 选择对象
		  input.setSelectionRange(0, content.length) //核心
		  let result = document.execCommand("Copy") // 执行浏览器复制命令
		  input.remove()
		 return result
	}
	
	static getBankNameByCode(code){
	      let tempCode=code.toLocaleUpperCase(); 
	      let codeList=[{code:"ICBC",name:"中国工商银行"},{code:"ABC",name:"中国农业银行"},{code:"CCB",name:"中国建设银行"},{code:"BCM",name:"交通银行"},{code:"CMBC",name:"民生银行"},{code:"CIB",name:"兴业银行"},{code: "SPDB", name: "浦发银行"},{code: "CNCB", name: "中信银行"},{code: "CEB", name: "光大银行"},{code: "CMB", name: "招商银行"},{code: "CGB", name: "广发银行"}, {code: "BOC", name: "中国银行"},{code: "HXB", name: "华夏银行"},{code: "PAB", name: "平安银行"},{code: "PSBC", name: "中国邮政"},{code: "BCCB", name: "北京银行"},{code: "SHB", name: "上海银行"},{code: "HRBB", name: "哈尔滨银行"},{code: "CZB", name: "浙商银行"},{code: "CSCB", name: "长沙银行"},{code: "QDCCB", name: "青岛银行"},{code: "ALIPAY", name: "支付宝"},{code: "WebMM", name: "微信支付"},{code: "QQPAY", name: "QQ钱包"},{code: "JDPAY", name: "京东钱包"},{code: "UNIPAY", name: "银联钱包/云闪付"},{code: "MEITUAN", name: "美团支付"},{code: "WXTM", name: "微信条码"},{code: "GDB", name: "广东发展银行"},{code: "ADBC", name: "农业发展银行"},{code: "RCC", name: "农村信用社"},{code: "CB", name: "商业银行"}]
	      for(let i=0;i<codeList.length;i++){
	          if(codeList[i].code==tempCode){
	              return codeList[i].name;
	              break;
	          }
	      }
	      return "";
	  }
	
	  static getBankCodeUpper(code){
	    let tempCode=code.toLocaleUpperCase(); 
	    return tempCode;
	}
	
	  /**
	   * 参数的AES对称加密
	   * @param data 参数的数据，未加密的
	   */
	  static paramAESEncrypt(data){
	    return CryptoJS.AES.encrypt(data,"com.wanluhui.www").toString();
	  }
	  /**
	   * 
	   * @param data  aes机密后的数据
	   */
	  static paramAESDecrypt(data){
	    return CryptoJS.AES.decrypt(data,"com.wanluhui.www").toString(CryptoJS.enc.Utf8)
	  }
	
	
	  /**
	   * 将url后面的参数反向序列为对象
	   * @param strUrl  格式:  incode=255374&f=123
	   */
	  static urlToObj(strUrl){
	    let string = strUrl.split('&');
			let res = {};
			for(let i = 0;i<string.length;i++){
				let str = string[i].split('=');
				if(str[0]!=''){
					res[str[0]]=str[1];
				}
			}
			return res;
	  }
	  /**
	   * php的时间戳转化为时间
	   * @param {Object} value  待转化的php时间戳
	   * @param {Object} args  参数"t"只有时分秒,"p"年月日时分秒,没有是年月日
	   */
	 static phpTimestampToDate(value,args=""){
		 let str = parseInt(value) * 1000;//将php时间戳转化为整形并乘以1000
		    let newDate = new Date(str);
		    let year = newDate.getUTCFullYear();//取年份
		    let month = newDate.getUTCMonth() + 1;//取月份
		     let monthStr="";
		     if(month<10){
		       monthStr="0"+month
		     }else{
		       monthStr=month+"";
		     }
		     let nowday = newDate.getUTCDate();//取天数
		     let nowdayStr="";
		     if (nowday >= 0 && nowday <= 9) {
		       nowdayStr = "0" + nowday;
		     } else {
		       nowdayStr = nowday + "";
		     }
		     let hour=newDate.getHours();
		     let min=newDate.getMinutes();
		     let second=newDate.getSeconds();
		     if(args=="t"){//只有时分秒
		         return hour+":"+min+":"+second;
		     }else if(args=="p"){//年月日，时分秒
		       return year + "-" + monthStr + "-" + nowdayStr+"  "+hour+":"+min+":"+second;
		     }
		     return year + "-" + monthStr + "-" + nowdayStr;  //默认是年月日
	 }

	 ////////////////////////////////////////下面是针对模板中使用
	 /**
		 * 模板上面使用的判断
		 * @param  value  目标值
		 * @param  symbol 逻辑判断的字符
		 * @param  val  长度的值
		 */
	static	strlenFun(value, symbol, val) {
			if (Tools.isEmpty(symbol)) {
				if (value.toString().length >= val) {
					return true;
				}
			} else {
				switch (symbol) {
					case '>':
						{
							if (value.toString().length > val) {
								return true;
							}
						}
						break;
					case '>=':
						{
							if (value.toString().length >= val) {
								return true;
							}
						}
						break;
					case '==':
						{
							if (value.toString().length == val) {
								return true;
							}
						}
						break;
					case '<':
						{
							if (value.toString().length < val) {
								return true;
							}
						}
						break;
					case '<=':
						{
							if (value.toString().length <= val) {
								return true;
							}
						}
						break;
				}
			}
			return false;
		}
		

}
export class Config {
	// #ifdef MP || APP-PLUS-NVUE || APP-PLUS
	static SERVER_PATH = "http://app.tw8999.com/"; //后面要以 "/" 结尾  http://app.tw8999.com/  http://app.wanluhui1.com/
	// #endif
	// #ifdef H5 
	static HOST = "http://app.tw8999.com/";
	static SERVER_PATH = "";
	// #endif
	static URL = "http://app.tw8999.com/";
	static VERSION = "1"; //访问的域名
	static IS_SHOW_CONSOLE_URL = true; //浏览器console面板是否显示调试的请求的URL
	static AES_KEY = "f54d0a62f7d032b0";
	static SUCCESS_CODE = 200;
	static FAIL_CODE = 500;
	static LOGIN_CODE = 1001;
	static BET_CHANGE_RATE = 5008;

	static isAgent = 0; //是否开启代理模式 1有代理(有邀请码强制填写),0无代理(无邀请码)
	static is3rd=true; //是否是第三方模式  ture是有第三方的游戏，false是没有第三方的游戏

	//六合彩中的合肖或自选不中的item_id
	static LHC_SXD_ITEMID = 264; //六合彩合肖
	static LHC_SLX_ITEMID = 1322; //六合彩自选不中
	static QLC_SXD_ITEMID = 64233; //极速六合彩合肖  
	static QLC_SLX_ITEMID = 64790; //极速六合彩自选不中

	static IS_LOGIN_STORE_KEY = "b53a5e1b388af2a2e13843e1aa9dc695"; //md5("isLogin")的值
	static ALL_LOT_STORE_KEY = "ed1bd1940b9705a299605b00000898df"; //md5("allLot")的值
	static PRESET_KEY = "d15dd3b3bc5b883535d4d8177b178de8"; //md5('preset')的值
	static FUID_KEY = "4b4a29d1ee53ef0a81e609ce00c06227"; //md5('fuid')   公司的Fuid
	static PLAYER_KEY = "912af0dff974604f1321254ca8ff38b6"; //md5('player') 玩法的数据存储
	static RATE_KEY = "67942503875c1ae74e4b5b80a0dade01"; //md5('rate') 倍率
	static MONEY_KEY = "9726255eec083aa56dc0449a21b33190"; //md5('money') 资金
	static USERINFO_KEY = "d0c0bc7b1930e34f5faf4666533189a2"; //md5('userinfo') 昵称
	static ROLE_KEY = "29a7e96467b69a9f5a93332e29e9b0de"; //md5('role') 角色
	static LOT_SOUND = "0b8263d341de01f741e4deadfb18f9eb"; //md5('sound')
	static RECOMMEND = "6a61e544f8626659b37e602df3eeab09"; //md5('recommend')
	static NOTICEDETAIL = "ddd4e7c37bdbc332c07e421895542f50"; //md5('noticedetail')
	static NOTICE_STATUS = "977ff5c053dc96b2d2553acc60d792f2"; //md5('noticestatus')
	static LOTTER_DETAIL_PARAMS="b2757c04feb3c4e50214138616615ed3";//md5('lotterDetailParams') 从彩种页面
	static LOTTER_MENU="d55cb84a6955816e026167a1c0a8bb23";//md5('lotmenu')
	static INCODE="94aeb32d71e9a9034bd25f2205bdf765";//md5('incode')
}

export class URL {
	//所有请求的API
	/**
	 * 接口的规范备注:  请求类型get/post/put/delete
	 */
	static USER_MAIN_HALL = "/user/MainHall"; //获取首页的分类消息
	static USER_TIME = "/user/time"; //盘口的剩余时间的处理
	static USER_GAMSYS = "/user/Gamsys"; //获取开奖的5条记录
	static USER_GAMSYSTIME = "/user/GamsysTime"; //刷新当前期结束时间
	static USER_GAMSYONE = "/user/GamsysOne"; //刷新最新一期结果
	static USER_PLAY = "/user/IndexM"; //彩票的玩法距离  参数:toplotcode
	static USER_MENU_MENU = "/file/Menu"; //菜单页面的菜单的接口显示
	static USER_LOTTERY = "/file/Lottery"; //侧滑菜单的值显示
	static USER_EDITREGION = "/user/EditRegion"; //修改用户盘口  参数:必填toplotid,region
	static USER_USEROUTCASH = "/user/useroutcash"; //申请提现 必填：bank_id银行卡id,out [cash：提现金额, password2：提现密码]  

	static LOGIN_LOGIN = "/login/login"; //登陆 参数username,password 
	static LOGIN_VCODE = "login/vcode"; //图片验证码
	static LOGIN_VCODENEW = "login/VcodeNew";//图片验证码
	static LOGIN_REGISTER = "/login/register"; //注册  参数:必填username,password,inviteCode,imgcode,mobile  （测试邀请码682724)
	static LOGIN_FINDPWD = "/login/findpwd"; //找回密码第一步获取验证码  必填:username , type(login登陆密码/charge提现密码)
	static LOGIN_MODIFYPWD = "/login/modifypwd"; //找回密码第二步处理数据  必填: username,password,code type(login登陆密码/charge提现密码)

	static USER_SHOWLOTS = "/user/ShowLots"; // 盘口数据  参数：必填code  可选lid,item_id,stype,is_fastkey,lotteryId
	static USER_FOLLOW = "/user/MyFollow"; //是否关注，参数:必填lotteryId,is_follow
	static USER_CONTENT = "/user/Content"; //首页的公告数据
	static USER_BANNER = "/user/Banner"; //首页的轮播图
	static USER_SHOWUSERINFO = "/user/ShowUserInfo"; //用户的信息
	static USER_EDITUSERINFO = "/user/EditUserInfo"; //编辑用户信息
	static USER_SHOWUSERBANK = "/user/ShowUserBank"; //查询银行卡信息
	static USER_DELUSERBANK = "/user/DelUserBank"; //删除银行卡 参数：必填bankid
	static USER_FINDCREDIT = "/user/FindCredit"; //钱包中的资产
	static USER_MONEY = "/user/money"; //今日输入，未结算
	static USER_EDITUSERBANK = "/user/EditUserBank"; //添加银行卡
	static USER_SHOWACCTOUT = "/user/showacctout"; //提现第一步
	static USER_SYSTEMUPDATE = "/user/SystemUpdate";//更新app的操作

	static USER_RECOMMENDAPP = "/menu/RecommendApp"; //推荐app
	static USER_TOKEN = "/user/Token"; //判断用户是否过期

	static USER_GAMRULE = "/menu/GamRule"; //用户的规则表  参数:必填toplotcode
	static USER_ORDERHIST = "/report/OrderHist"; //报表查询 参数:必填sdate,edate,可选gameType
	static LOTSGAM_ORDERDETAIL = "/lotsgam/orderdetail"; //报表今日已结(未结) 参数:必填page,is_hit(1已结,0未结), 可选pageSize条数
	static LOTTERY_INDEX = "/lottery/index"; //开奖结果 参数:必填topcode彩种,time日期，page页码
	static LOTTERY_CREATEORDER = "/lottery/createorder"; //下注的处理 参数lotcode 必填，rows必填为数组 一条数据为{'tid':'','balls':'','cash':'','rate':''}
	static LOTTERY_FASTORDER = "/lottery/fastorder"; //快捷的投注 参数row必填 ，里面的数据是数组{"id":'','cash':'','lotcode':''}
	static LOTTERY_GETODDS = "/lottery/getodds"; //获取盘口的数据   参数:必填topcode
	static LOTTERY_OPENLOTTERY = "/lottery/openlottery"; //获取倍率页面的开奖结果的数据  参数: 必填topcode ,type  1为最新一条5为获取5条数据
	static LOTTERY_COMBRATE = "/lottery/combrate"; //合肖和自选不中获取赔率 参数:
	static COMMON_SETINFO = "/common/setinfo"; //判断赔率是否有更新 参数：必选 topcode  

	static FILE_RECHARGEWITHDRAWAL = "/file/RechargeWithdrawal"; //体现充值的菜单显示或者隐藏
	static MENU_SHOWACCTLISTS = "/menu/showAcctLists"; //我的钱包的列表
	static MMNU_SHOWACCTLIST = "/menu/showAcctList"; //我的钱包-查看教育明细


	static LOGIN_TESTPLAY = "/login/testplay"; //试玩

	static OTHER_CONFIG = "/other/config"; //网站的一些配置 参数:必填type   常见问题：questions、加盟：join、推荐：recommend、优惠活动：promotes, 提现充值:transaction
  	static OTHER_USERINCASH = "/other/userincash"; //获取充值的链接
  	static OTHER_INCASH = "/other/incashnew"; //支付的第一步获取的数据
  	static OTHER_INCASH2 = "/other/incash2new"; //支付的第二步操作
  	static OTHER_NETPAY = "/other/netpaynew"; //网银跳转到网页的处理
  	static COMMON_SET = "/common/set"; //获取设置的值并存储，里面有是否数据加密的处理
  	static OTHER_UPLOAD = "/other/upload"; //上传用户的头像
	static OTHER_UPLOAD_BLOB = "/other/uploadBlob"; //上传用户的头像

	static ALERT_CONTENT = "/user/alertcontent"; //首页的弹窗公共
	static ALL_CONTENT = "/user/allcontent"; //公共列表
	
	



	  // 第三的游戏接口
	static THIRD_GETENTERTAINMENTPLAYLIST="/Thirdpartygame/GetEntertainmentPlayList"; //获取真人游戏的列表
	static THIRD_GETENTERTAINMENTPLAYURL="/Thirdpartygame/GetEntertainmentPlayUrl";//获取游戏的玩法的链接
	static THIRD_GETELECTRONICGAMELIST="/Thirdpartygame/GetElectronicGameList";//获取游戏的列表
	static THIRD_GETELECTRONICGAMEURL="/Thirdpartygame/GetElectronicGameUrl";//获取游戏具体的链接
	static THIRD_SHOWTRANS="/Thirdpartygame/ShowTrans"; //获取转化金额中的资产
	static THIRD_GETPLATFORMNAMES="/Thirdpartygame/GetPlatformNames";//获取第三方的游戏平台的名称
	static THIRD_GAMETRANS="/Thirdpartygame/Trans";//账户的余额互转
	static THIRD_ALLTRANS="/Thirdpartygame/AllTrans";//其它的平台都转回到中心钱包(回收)
	static THIRD_REPORTLIST="/Thirdpartygame/ReportList";//第三方的报表列表
	static THIRD_REPORTINFO="/Thirdpartygame/ReportInfo";//获取报表具体的详细信息
	
	static OTHER_BALANCE="/other/balance";//有第三方的余额和今日可赢的数据
	static THIRD_GETSPORTSEVENTSLIST="/Thirdpartygame/GetSportsEventsList";//获取第三方的体育列表数据
	static THIRD_GETSPORTSEVENTSURL="/Thirdpartygame/GetSportsEventsUrl";//获取第三方的体育的链接数据
	
	
	static LOTSGAM_GETCHANGLONG="/Lotsgam/GetChanglong";//长龙
	static LOTTERY_CHANGLONGCREATEORDER="/lottery/changlongCreateorder";//长龙的投注
	
	  //第三方游戏利己SBO
	static THIRD_GETSPORTSBOOKLIST="/Thirdpartysbogame/GetSportsBookList";//获取sbo游戏列表
	static THIRD_GETSPORTSBOOKURL="/Thirdpartysbogame/GetSportsBookUrl"; //获取sbo游戏的链接
	static THIRD_SBOREPORTLIST="/Thirdpartysbogame/ReportList";//sbo利己报表
	static THIRD_SBOREPORTINFO="/Thirdpartysbogame/ReportInfo";//sbo利己报表详细
	  
	  //第三方游戏开元棋牌
	static THIRD_KYGAME_GETSHOWLIST="/Thirdpartykygame/GetShowList"; //获取开元棋牌游戏列表
	static THIRD_KYGAME_GETCHESSGAMESURL="/Thirdpartykygame/GetChessGamesUrl"; //获取开元棋牌游戏入口
	static THIRD_KYGAME_REPORTLIST="/Thirdpartykygame/ReportList"; //获取开元棋牌报表
	static THIRD_KYGAME_REPORTINFO="/Thirdpartykygame/ReportInfo"; //获取开元棋牌报表详细
}

export class VueTools {
	static setStorageSync(key, data) {
		try {
			uni.setStorageSync(key, data);
		} catch (e) {
			console.log("setStorageSync:存储数据失败");
		}
	}

	static clearAndSetStorageSync(key, data) {
		VueTools.removeStorageSync(key);
		VueTools.setStorageSync(key, data);
	}

	static clearStorageSync() {
		try {
			uni.clearStorageSync();
		} catch (e) {
			console.log("clearStorageSync:清除所有数据失败");
		}
	}

	static getStorageSync(key) {
		try {
			const value = uni.getStorageSync(key);
			return value;
		} catch (e) {
			console.log("getStorageSync:获取数据失败");
		}
	}
	static removeStorageSync(key) {
		try {
			const value = uni.removeStorageSync(key);
			return value;
		} catch (e) {
			console.log("removeStorageSync:移除存储数据失败");
		}
	}

	static toastNo(title, duration = 1000) {
		uni.showToast({
			title: title,
			icon: 'none',
			duration: duration
		});
	}

}

export class Net {

	/**
	 * 判断url是否有字符串 ./assets或http或https
	 * @param {String} url
	 * @return {boolean}  false是有指定字符
	 */
	static needContextPrefix(url) {
		return !(url.indexOf('./assets') == 0 || url.indexOf('http') == 0 || url.indexOf('https') == 0);
	}
	/**
	 * 拼接url的地址
	 * @param {String} url
	 */
	static requestUrl(url) {
		let urlStr = "";
		if (typeof url === 'string') {
			urlStr = url;
		}
		if (this.needContextPrefix(urlStr)) {
			url = Config.SERVER_PATH + '' + url
		}
		return url;
	}

	/**
	 * get请求
	 * @param {String}   urlStr  是请求的url
	 * @param {Object}   params 是传递的参数 对象{}
	 * @param {Object}   headerStr 是头部的参数 对象{}
	 * @param {function}   successCall 成功后的回调有一个参数是结果值
	 * @param {function}   failCall 是失败后的回调函数
	 * @param {String} method 值为POST/GET 的大写
	 * @param {Object} extraParams 是传递额外的参数拼接到url上面  对象{}  
	 */
	static ayiHttp(urlStr, params = {}, successCall, failCall = null,extraParams={},method = 'POST') {
		urlStr = Net.requestUrl(urlStr);

		let token = Tools.getBodyAttribute("token");
		let sessid = Tools.getBodyAttribute("sessid");
		let encrypt = Tools.getBodyAttribute("encrypt");
		encrypt = (!Tools.isEmpty(encrypt) && encrypt == '1') ? 1 : 0;
		let baseParam;
		if (Tools.isEmpty(sessid)) {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"encrypt": encrypt
			};
		} else {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"sessid": sessid,
				"encrypt": encrypt
			};
		}
		if(!Tools.isEmpty(extraParams)){
			baseParam=Tools.concat(baseParam, extraParams);
		}
		urlStr = Tools.Urlsplice(baseParam, urlStr);
		if (Config.IS_SHOW_CONSOLE_URL) {
			console.log("requireURL:"+urlStr);
		}
		uni.request({
			url: urlStr,
			method: method,
			data:params,			
			header: {
				'Content-Type': 'application/json'
			},
			success: (res) => {
				successCall(res.data);
			},
			fail: (err) => {
				console.log("错误error:", err);
				failCall(err);
			}
		});
	}

	static ayiHttpGet(urlStr, params = {}, successCall, failCall = null) {
		urlStr = Net.requestUrl(urlStr);
	
		let token = Tools.getBodyAttribute("token");
		let sessid = Tools.getBodyAttribute("sessid");
		let encrypt = Tools.getBodyAttribute("encrypt");
		encrypt = (!Tools.isEmpty(encrypt) && encrypt == '1') ? 1 : 0;
		let baseParam;
		if (Tools.isEmpty(sessid)) {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"encrypt": encrypt,
				//"role":"test"
			};
		} else {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"sessid": sessid,
				"encrypt": encrypt,
				//"role":"test"
			};
		}
		if (Tools.isEmpty(params)) {
			urlStr = Tools.Urlsplice(baseParam, urlStr);
		} else {
			//参数暂时还是没有加密的一种方式
			let concatParam = Tools.concat(baseParam, {
				"data": params
			});
			urlStr = Tools.Urlsplice(concatParam, urlStr);
		}
		if (Config.IS_SHOW_CONSOLE_URL) {
			console.log("requireURL:", urlStr);
		}
		uni.request({
			url: urlStr,
			method: 'GET',
			header: {
				'Content-Type': 'application/json'
			},
			success: (res) => {
				successCall(res.data);
			},
			fail: (err) => {
				console.log("错误error:", err);
				failCall(err);
			}
		});
	}
	
	/**
	 * 备份的网络请求方法不作为实际的使用,只做为参考使用
	 */
	static ayiHttpBark(urlStr, params = {}, successCall, failCall = null, method = 'POST') {
		urlStr = Net.requestUrl(urlStr);
	
		let token = Tools.getBodyAttribute("token");
		let sessid = Tools.getBodyAttribute("sessid");
		let encrypt = Tools.getBodyAttribute("encrypt");
		encrypt = (!Tools.isEmpty(encrypt) && encrypt == '1') ? 1 : 0;
		let baseParam;
		if (Tools.isEmpty(sessid)) {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"encrypt": encrypt
			};
		} else {
			baseParam = {
				"token": Tools.isEmpty(token) ? "" : token,
				"sessid": sessid,
				"encrypt": encrypt
			};
		}
		if (Tools.isEmpty(params)) {
			urlStr = Tools.Urlsplice(baseParam, urlStr);
		} else {
			//参数暂时还是没有加密的一种方式
			let concatParam = Tools.concat(baseParam, {
				"data": params
			});
			urlStr = Tools.Urlsplice(concatParam, urlStr);
		}
		if (Config.IS_SHOW_CONSOLE_URL) {
			console.log("requireURL:", urlStr);
		}
		uni.request({
			url: urlStr,
			method: method,
			header: {
				'Content-Type': 'application/json'
			},
			success: (res) => {
				successCall(res.data);
			},
			fail: (err) => {
				console.log("错误error:", err);
				failCall(err);
			}
		});
	}

}
